<template>
	<view class="create_notice_box">
		<Tips/>
		<MyNull img="createNotice.png" height="calc(30vh)"/>
		<MyInput :focus="false" :borderColor="primary_cool_color" label="标题" v-model="formData.title"></MyInput>
		<view class="content">
			<uni-easyinput :primaryColor="primary_cool_color" type="textarea" v-model="formData.content" placeholder="请输入内容" />
		</view>
		<view class="submit">
			<MyButton :bgc="primary_hot_color" :clickFun="createNoticeFun">发布</MyButton>
		</view>
	</view>
</template>

<script setup>
	import {ref} from 'vue'
	
	import MyInput from '@/components/MyInput/MyInput.vue'
	import Tips from '@/components/Tips/Tips.vue'
	import MyButton from '@/components/MyButton/MyButton.vue'
	import MyNull from '@/components/MyNull/MyNull.vue'
	
	import {
		dynamicStyleStore
	} from '@/stores/dynamicStyle.js'
	
	import {
		DormitoryModel
	} from '@/service/model/dormitory.js'
	
	import {
		verifyIsLogin,
		verifyFormData
		} from '@/hooks/verify.js'
	
	const dynamicStyle_store = dynamicStyleStore()
	const dormitoryModel = new DormitoryModel()
	
	const {
		primary_hot_color,
		primary_cool_color
	} = dynamicStyle_store.dormitoryStyle
	
	const formData = ref({
		title:'',
		content:''
	})
	
	const formDataSchema={
		title:{
			required:true,
			tip:'标题'
		},
		content:{
			required:true,
			tip:'内容'
		}
	}
	
	const dormitoryAllId=uni.getStorageSync('homeData')
	
	//创建公告
	const createNoticeFun=async()=>{
		verifyIsLogin()
		verifyFormData(formData.value,formDataSchema)
		const {data,success}=await dormitoryModel.postCreateNotice(formData.value,dormitoryAllId.dormitory_id)
		
		if(success){
			uni.$emit('tips',data,'success')
			setTimeout(()=>{
				uni.navigateBack()
			},300)
		}
	}
</script>

<style lang="less">
	.create_notice_box{
		margin-top: 30rpx;
		.content{
			padding: 30rpx;
		}
		.submit{
			padding: 30rpx;
		}
	}
</style>
